﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HamcoWcs.Models.Monitors
{
    public class ErrorBitInfo
    {

        public string Name { get; set; }

        public string DeviceName{ get; set; }
        public int Offset { get; set; }
        public int Bit { get; set; }

        public int CurrentValue { get; set; } = -1;
        public int OldValue { get; set; } = -1;

        public void GetTargetBit(byte[] dbBlock)
        {
            try
            {
                var a = (dbBlock[Offset] >> Bit) & 1;
                OldValue = CurrentValue;
                CurrentValue = a;
            }
            catch (Exception)
            {
                CurrentValue = -2;
            }
        }

        public ErrorBitInfo()
        {
            
        }

        public ErrorBitInfo(string deviceName,string name, int offset, int bit)
        {
            DeviceName = deviceName;
            Name = name;
            Offset = offset;
            Bit = bit;
        }
    }

}
